﻿using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ClassLibrary1.Templates
{
    public class DapperIDALTemplate : TemplatesBase
    {
        public DapperIDALTemplate() : base("IDal")
        {
        }

        /// <summary>
        /// 命名空间
        /// </summary>
        public override string namespacestr
        {
            get
            {
                return Entrance.attrnamespacestr + ".DAL";
            }
        }

        public override void SaveFile(List<EntityAttrList> list)
        {
            if (list != null && list.Count > 0)
            {
                StringBuilder stringBuilder = new StringBuilder();
                //表描述
                string txtTableDesc = list.FirstOrDefault().TableDescription;
                string txtTableName = list.FirstOrDefault().TableName;
                stringBuilder.AppendLine("using System;");
                stringBuilder.AppendLine("");
                stringBuilder.AppendLine("namespace " + namespacestr);
                stringBuilder.AppendLine("{");
                stringBuilder.Append(new string(' ', 4));
                stringBuilder.AppendLine("/// <summary>");
                stringBuilder.Append(new string(' ', 4));
                stringBuilder.AppendLine("/// " + txtTableDesc + "数据接口层");
                stringBuilder.Append(new string(' ', 4));
                stringBuilder.AppendLine("/// <summary>");
                stringBuilder.Append(new string(' ', 4));
                stringBuilder.AppendLine("public interface I" + txtTableName + "Dal");
                stringBuilder.Append(new string(' ', 4));
                stringBuilder.AppendLine("{");


                stringBuilder.AppendLine("");


                stringBuilder.Append(new string(' ', 4));
                stringBuilder.AppendLine("}");
                stringBuilder.AppendLine("}");
                CreateFile("I" + txtTableName, stringBuilder.ToString(), "Dal");
            }
        }
    }
}
